
// 实现楼层滚动

$(function () {
    // 根据点击不同的 楼层按钮到 不同位置.主要是根据 scrollTop来完成
    let arr = ["red", "skyblue", "palegreen", "plum", "salmon", "crimson"]
    let a = 0
    let isAnimate = true;

    $('.left-select ul li').on("mouseenter", function () {
        $(this).css('backgroundColor', arr[a++])
        if (a == arr.length - 1) a = 0
    })

    $('.left-select ul li').on("mouseleave", function () {
        $(this).css('backgroundColor', "#fff")

    })
    $('.left-select ul li').on('click', function () {


        let index = $(this).index();
        let offset;

        if (index == 0) {
            offset = $('.goods').offset().top;
        } else if (index < 5) {
            offset = $('.main .scroll-f>div').eq(index - 1).offset().top
        } else {
            offset = 0
        }
        if (isAnimate) {
            $('html,body').animate({ "scrollTop": offset }, 500, function () {
                isAnimate = true
            })
        }
        isAnimate = false;
    })

    // 滚动事件
    let scroll;

    $(window).on('scroll', docTop(scrollFixed))

    function scrollFixed() {

        scroll = $(this).scrollTop();
        if (scroll >= 400) {
            // input的转换
            if ($('#search_f').val().trim() != "" && $('#search_t').prop("value").trim() != $('#search_f').prop("value").trim()) {
                $('#search_t').val($('#search_f').val());
            }
            // 导航栏的固定
            $(".tt-nav").slideDown(400).css("position", "fixed")
            $(".nav-tt").css('display', "none")
        } else {
            // input的转换
            if ($('#search_t').prop("value").trim() != $('#search_f').prop("value").trim()) {
                $('#search_f').val($('#search_t').val());
            }
            // 导航栏的固定
            $(".tt-nav").slideUp(0).css("position", "absolute")
            $(".nav-tt").css('display', "block")
        }
        //底部隐藏    
        if (scroll >= 2000 && scroll <= 4222) {
            $('.left-select').css('position', 'fixed')
            $('.ewm-t').css('position', 'fixed')
        } else {
            $('.left-select').css('position', 'absolute')
            $('.ewm-t').css('position', 'absolute')
        }

    }

    function docTop(fn, ...arg) {

        let timer;
        return function () {
            that = this
            timer && clearTimeout(timer)
            timer = setTimeout(function () {
                fn.call(this, arg);
            }, 50)
        }
    }





    // table栏
    $(".menu>ul>li").hover(function () {
        $(this).children('.shows').css('display', 'block').parent('.show').siblings().find('.shows').css('display', 'none')
    }, function () {
        $(this).find('.shows').css('display', 'none')
    })


    // 倒计时开始
    function djs() {
        let count = 10
        let timer2
        let target = new Date('2021-5-15 18:00:00').getTime();
        let hour = $('.djs-time').children("div").eq(0);
        let minute = $('.djs-time').children("div").eq(1);
        let second = $('.djs-time').children("div").eq(2);
        function addZero(num) {
            return num < 10 ? '0' + num : num;
        }
        let f = true;

        let time = setInterval(timer, 1000)
        timer();
        function timer() {
            let now = Date.now();
            let dis = target - now;

            let s = Number(Math.floor(dis / 1000 % 60));
            let m = Number(Math.floor(dis / 1000 / 60 % 60));
            let h = Number(Math.floor(dis / 1000 / 60 / 60 % 60));

            if (s <= 0 && m <= 0 && h <= 0) {
                clearInterval(time)
                $('.djs-time').css('display', "none");
                $('.djs-time').before(`<div class="tt-m">下一场秒杀还剩:${count} </div>`)
                timer2 = setInterval(function () {
                    count--
                    $('.tt-m').text(`下一场秒杀还剩:${count}`)
                    if (count <= 0) {
                        $('.tt-m').remove();
                        clearInterval(timer2)
                        count = 10
                        target = now + 7200000
                        $('.djs-time').css('display', "block");
                        dis = target - now;
                        s = Number(Math.floor(dis / 1000 % 60));
                        m = Number(Math.floor(dis / 1000 / 60 % 60));
                        h = Number(Math.floor(dis / 1000 / 60 / 60 % 60));
                        h = addZero(h);
                        m = addZero(m);
                        s = addZero(s);
                        b(h, m)
                        second.text(s)
                        time = setInterval(timer, 1000)
                    }
                }, 1000)

            }

            if (s == 0 || f) {
                h = addZero(h);
                m = addZero(m);
                b(h, m)
                f = false;
            }
            h = addZero(h);
            m = addZero(m);
            s = addZero(s);
            second.text(s)
        }

        function b(h, m) {
            hour.text(h)
            minute.text(m)
        }


    }
    djs()
    // 倒计时结束




    // 点击切换开始
    let p = 0
    function toggles(that) {
        let a = that.parents(".product-b").children(".product-p").children("img:nth-child(1)");
        let b = that.parents(".product-b").children(".product-p").children("img:nth-child(2)");
        let c = that.parents(".product-b").children(".product-p").children("img:nth-child(3)");
        if (p == 1) {
            a.css('display', "none")
            b.css('display', "block")
            c.css('display', "none")
        } else if (p == 2) {
            a.css('display', "none")
            b.css('display', "none")
            c.css('display', "block")
        } else if (p == 0) {
            a.css('display', "block")
            b.css('display', "none")
            c.css('display', "none")
        }
    }
    $('.left-btn').on("click", function () {
        p++;
        if (p == 3) {
            p = 0
        }
        toggles($(this))
    })

    $('.right-btn').on("click", function () {

        p--;
        if (p < 0) {
            p = 2
        }
        toggles($(this))
    })
    // 点击切换结束




    // 服装配置的table切换
    function fzTable(btn, selector, style) {
        $(btn).on("click", function () {
            $(this).addClass(style).siblings().removeClass(style)
            let index = $(this).index();
            $(selector).eq(index).removeClass('hide').siblings(selector).addClass('hide')
        })
    }
    fzTable(".f-one", ".fzps-togg", "active-f");
    fzTable(".m-one", ".mytz-togg", "active-w");
    fzTable(".j-one", ".jzrs-togg", "active-j");
    fzTable(".sh-one", ".jjsh-togg", "active-jjsh");



    // 输入框的传值;






})














